package service.AOP.defineAOP;

import org.aspectj.lang.ProceedingJoinPoint;

/**
 * @Description ${DESCRIPTION}.
 * @author: wwchen
 * @DateTime: 2018-05-13 15:07
 */

public class AOPMessage {
    public void logger(){
        System.out.println("这是AOP日志打印");
    }

    /**
     * 正常返回执行
     */
    public void afterReturning(){
        System.out.println("这是AOP日志打印-执行成功返回 ");
    }

    /**
     * 抛出异常执行
     */
    public void afterThroeing(){
        System.out.println("异常抛出后执行");
    }

    public void after(){
        System.out.println("after打印");
    }

    /**
     * 环绕通知，必须带ProceedingJoinPoint参数
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕事件");
        Object object =joinPoint.proceed();
        System.out.println("环绕事件1");
        return object;
    }

    /**
     * 带参数的环绕通知，如果某个实现类也是带有String，int参数则会使用该通知
     * @param joinPoint
     * @param str
     * @param num
     * @return
     * @throws Throwable
     */
    public Object aroundInit(ProceedingJoinPoint joinPoint, String str, int num) throws Throwable {
        System.out.println("环绕事件 "+str+" "+num);
        Object object =joinPoint.proceed();
        System.out.println("环绕事件1 "+str+" "+num);
        return object;
    }

}
